
#include <BAction>
#include "member_BAction.h"

using namespace BWE;

#define member					(*(member_BAction*)_ptr)
#define member_allocate()		_ptr = new member_BAction(this)
#define member_release()		delete (member_BAction*)_ptr

BAction::BAction()
{
	member_allocate();
}
BAction::BAction(const BString& text)
{
	member_allocate();
	setText(text);
}
BAction::BAction(BIcon* icon, const BString& text)
{
	member_allocate();
	setIcon(icon);
	setText(text);
}
BAction::~BAction()
{
	member_release();
}

void BAction::setText(const BString& text)
{
	if(member.text != text)
	{
		member.text = text;
		member.dirty = true;
		emit(Signal_TextChanged, member.text);
		if (member.host)
			member.host->fresh();
	}
}
const BString& BAction::text() const
{
	return member.text;
}

void BAction::setIcon(BIcon* icon)
{
	if (member.icon != icon)
	{
		member.icon = icon;
		member.dirty = true;
		emit(Signal_ImageChanged, member.icon);
		if (member.host)
			member.host->fresh();
	}
}
BIcon* BAction::icon()
{
	return member.icon.ptr();
}
const BIcon* BAction::icon() const
{
	return member.icon.ptr();
}

void BAction::setGraph(Graph graph)
{
	if (member.graph != graph)
	{
		member.graph = graph;
		member.dirty = true;
		emit(Signal_GraphChanged, member.graph);
		if (member.host)
			member.host->fresh();
	}
}
Graph BAction::graph() const
{
	return member.graph;
}

void BAction::setCheckable(bool checkable)
{
	if(member.checkable != checkable)
	{
		member.checkable = checkable;
		member.checked = false;
		member.dirty = true;
		if (member.host)
			member.host->fresh();
	}
}
bool BAction::checkable() const
{
	return member.checkable;
}

void BAction::setChecked(bool checked)
{
	if(member.checkable && member.checked != checked)
	{
		member.checked = checked;
		member.dirty = true;
		if (member.host)
			member.host->fresh();
		emit(Signal_Checked, member.checked);
	}
}
bool BAction::checked() const
{
	return member.checked;
}

void BAction::trigger()
{
	if (this->enabled())
	{
		emit(Signal_Triggered, member.checked);
	}
}
